package se.webbzon.oschi01.json;

import java.io.IOException;
import java.io.PrintStream;

public class JsonString implements JsonLeaf<String> {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 2713112251187957046L;
	
	protected String str;
	
	public JsonString() {
		this((String) null);
	}
	
	public JsonString(JsonString other) {
		this(other.str);
	}
	
	public JsonString(String str) {
		this.str = str == null ? "" : str;
	}

	@Override public Type getType() {
		return JsonType.Type.String;
	}
	
	@Override public String toString() {
		return "\"" + str + "\"";
	}
	
	@Override public int hashCode() {
		return str.hashCode();
	}

	@Override public String getValue() {
		return str;
	}

	@Override public void setValue(String str) {
		this.str = str == null ? "" : str;
	}
	
	@Override public JsonString clone() {
		return new JsonString(this);
	}

	@Override public int compareTo(JsonLeaf<String> o) {
		return getValue().compareTo(o.getValue());
	}
	
	@Override public boolean equals(Object obj) {
		if (obj instanceof JsonLeaf)
			return getValue().equals(((JsonLeaf<?>) obj).getValue());
		else
			return false;
	}

	@Override public void printTo(PrintStream ps) throws IOException {
		ps.print(toString());
	}
	
}
